<template>
	<div class="card__body-container layout-padding">
		<el-card shadow="hover" class="layout-padding-auto">
			<el-divider content-position="left">开发上传素材配置</el-divider>
			<ImageUploadCOS v-model="state.material" :fileType="['png', 'jpg', 'jpeg', 'webp', 'bmp', 'xlsx', 'xls']" path="material" is-material />
			<el-divider content-position="left">基础配置</el-divider>
			<el-form :model="state.h5BasicsForm" inline>
				<el-form-item label="礼品Banner图(中文)">
					<ImageUploadCOS v-model="state.h5BasicsForm.list.gift_thumb" path="gift" />
				</el-form-item>
				<el-form-item label="礼品Banner图(英文)">
					<ImageUploadCOS v-model="state.h5BasicsForm.list.gift_thumb_en" path="gift" />
				</el-form-item>
				<el-form-item label="礼品Banner图(老挝)">
					<ImageUploadCOS v-model="state.h5BasicsForm.list.gift_thumb_lo" path="gift" />
				</el-form-item>
				<el-form-item label="APP安装包">
					<ImageUploadCOS
						v-model="state.h5BasicsForm.list.app_apk"
						isOtherFile
						path="app"
						:fileType="['zip', 'tar.gz', 'tar.bz2', 'tar.xz', 'tar.Z', 'Rar']"
						:fileSize="10"
					/>
				</el-form-item>
				<br />
				<el-form-item label="商品评论">
					<el-radio-group v-model="state.h5BasicsForm.list.product_review">
						<el-radio :value="1">开启</el-radio>
						<el-radio :value="0">关闭</el-radio>
					</el-radio-group>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="onSubmit('h5_basics_config')" :loading="state.submitLoading" size="default">保 存 </el-button>
				</el-form-item>
			</el-form>
			<el-divider content-position="left">佣金默认比例配置</el-divider>
			<el-form :model="state.commissionForm" inline>
				<el-form-item label="铜牌会员佣金占平台服务费比例">
					<el-input
						v-model="state.commissionForm.list.one_service_rate"
						placeholder="请输入佣金比例"
						@input="onVerifyNumberIntegerAndFloatOneServiceRate"
					>
						<template #append>%</template>
					</el-input>
				</el-form-item>
				<el-form-item label="银牌会员佣金占平台服务费比例">
					<el-input
						v-model="state.commissionForm.list.two_service_rate"
						placeholder="请输入佣金比例"
						@input="onVerifyNumberIntegerAndFloatTwoServiceRate"
					>
						<template #append>%</template>
					</el-input>
				</el-form-item>
				<el-form-item label="金牌会员佣金占平台服务费比例">
					<el-input
						v-model="state.commissionForm.list.three_service_rate"
						placeholder="请输入佣金比例"
						@input="onVerifyNumberIntegerAndFloatThreeServiceRate"
					>
						<template #append>%</template>
					</el-input>
				</el-form-item>
				<el-form-item label="银牌会员培养收入所占比例">
					<el-input
						v-model="state.commissionForm.list.tow_income_rate"
						placeholder="请输入所占比例"
						@input="onVerifyNumberIntegerAndFloatTowIncomeRate"
					>
						<template #append>%</template>
					</el-input>
				</el-form-item>
				<el-form-item label="金牌会员培养收入所占比例">
					<el-input
						v-model="state.commissionForm.list.three_income_rate"
						placeholder="请输入所占比例"
						@input="onVerifyNumberIntegerAndFloatThreeIncomeRate"
					>
						<template #append>%</template>
					</el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="onSubmit('commission_config')" :loading="state.submitLoading" size="default">保 存 </el-button>
				</el-form-item>
			</el-form>
			<el-divider content-position="left">用户手动升级配置</el-divider>
			<el-form :model="state.upgradeForm" inline>
				<el-form-item label="铜牌会员升级为银牌会员要求：直推铜牌会员人数达到">
					<el-input
						v-model="state.upgradeForm.list.one_to_two.recommend_num"
						placeholder="请输入条件人数"
						@input="onVerifiyNumberIntegerOneToTwoRecommendNum"
					>
						<template #append>个</template>
					</el-input>
				</el-form-item>
				<el-form-item label="铜牌总人数达到">
					<el-input v-model="state.upgradeForm.list.one_to_two.all_num" placeholder="请输入条件人数" @input="onVerifiyNumberIntegerOneToTwoAllNum">
						<template #append>个</template>
					</el-input>
				</el-form-item>
				<br />
				<el-form-item label="银牌会员升级为金牌会员要求：直推银牌会员人数达到">
					<el-input
						v-model="state.upgradeForm.list.two_to_three.recommend_num"
						placeholder="请输入条件人数"
						@input="onVerifiyNumberIntegerTowToThreeRecommendNum"
					>
						<template #append>个</template>
					</el-input>
				</el-form-item>
				<el-form-item label="银牌总人数达到">
					<el-input
						v-model="state.upgradeForm.list.two_to_three.all_num"
						placeholder="请输入条件人数"
						@input="onVerifiyNumberIntegerTowToThreeAllNum"
					>
						<template #append>个</template>
					</el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="onSubmit('upgrade_config')" :loading="state.submitLoading" size="default">保 存 </el-button>
				</el-form-item>
			</el-form>
			<el-divider content-position="left">订单配置</el-divider>
			<el-form :model="state.orderForm" inline>
				<el-form-item label="待支付自动关闭时间">
					<el-input v-model="state.orderForm.list.auto_cancel" placeholder="请输入待支付自动关闭时间" @input="onVerifiyNumberIntegerAutoCancel">
						<template #append>
							<el-select v-model="state.orderForm.list.cancel_unit" style="width: 65px">
								<el-option label="秒" :value="1" />
								<el-option label="分" :value="60" />
								<el-option label="时" :value="3600" />
								<el-option label="天" :value="86400" />
							</el-select>
						</template>
					</el-input>
				</el-form-item>
				<el-form-item label="发货自动确认收货时间">
					<el-input v-model="state.orderForm.list.auto_complete" placeholder="请输入发货自动确认收货时间" @input="onVerifiyNumberIntegerAutoComplete">
						<template #append>
							<el-select v-model="state.orderForm.list.complete_unit" style="width: 65px">
								<el-option label="秒" :value="1" />
								<el-option label="分" :value="60" />
								<el-option label="时" :value="3600" />
								<el-option label="天" :value="86400" />
							</el-select>
						</template>
					</el-input>
				</el-form-item>
				<el-form-item label="确认收货自动结算时间">
					<el-input v-model="state.orderForm.list.auto_settle" placeholder="请输入确认收货自动结算时间" @input="onVerifiyNumberIntegerAutoSettle">
						<template #append>
							<el-select v-model="state.orderForm.list.settle_unit" style="width: 65px">
								<el-option label="秒" :value="1" />
								<el-option label="分" :value="60" />
								<el-option label="时" :value="3600" />
								<el-option label="天" :value="86400" />
							</el-select>
						</template>
					</el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="onSubmit('order_config')" :loading="state.submitLoading" size="default">保 存 </el-button>
				</el-form-item>
			</el-form>
			<el-divider content-position="left">默认金牌会员配置</el-divider>
			<el-form :model="state.defaultThreeMobileForm" inline>
				<el-form-item label="金牌会员手机号">
					<el-input v-model="state.defaultThreeMobileForm.list" placeholder="请输入默认会员手机号" @input="onVerifiyNumberIntegerMobile" />
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="onSubmit('default_three_mobile')" :loading="state.submitLoading" size="default">保 存 </el-button>
				</el-form-item>
			</el-form>
			<el-divider content-position="left">有道云翻译配置</el-divider>
			<el-form :model="state.youdaoyunForm" inline>
				<el-form-item label="appKey">
					<el-input v-model="state.youdaoyunForm.list.appKey" placeholder="请输入appKey" />
				</el-form-item>
				<el-form-item label="appSecret">
					<el-input v-model="state.youdaoyunForm.list.appSecret" placeholder="请输入appSecret" />
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="onSubmit('youdaoyun_config')" :loading="state.submitLoading" size="default">保 存 </el-button>
				</el-form-item>
			</el-form>
			<el-divider content-position="left">短信配置</el-divider>
			<el-form :model="state.chuanglanForm" inline>
				<el-form-item label="国内账号">
					<el-input v-model="state.chuanglanForm.list.domestic.spid" placeholder="请输入账号" />
				</el-form-item>
				<el-form-item label="国内密码">
					<el-input v-model="state.chuanglanForm.list.domestic.password" placeholder="请输入密码" />
				</el-form-item>
				<el-form-item label="国内短信URL">
					<el-input v-model="state.chuanglanForm.list.domestic.send_url" placeholder="请输入短信URL" />
				</el-form-item>
				<br />
				<el-form-item label="国际账号">
					<el-input v-model="state.chuanglanForm.list.international.spid" placeholder="请输入账号" />
				</el-form-item>
				<el-form-item label="国际密码">
					<el-input v-model="state.chuanglanForm.list.international.password" placeholder="请输入密码" />
				</el-form-item>
				<el-form-item label="国际短信URL">
					<el-input v-model="state.chuanglanForm.list.international.send_url" placeholder="请输入短信URL" />
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="onSubmit('chuanglan_config')" :loading="state.submitLoading" size="default">保 存 </el-button>
				</el-form-item>
			</el-form>
			<el-divider content-position="left">支付配置</el-divider>
			<el-form :model="state.rateForm" inline>
				<el-form-item label="平台支付费率">
					<el-input v-model="state.rateForm.list.pay_rate" @input="onVerifyNumberIntegerAndFloatPayRate" placeholder="请输入平台支付费率">
						<template #append>‰</template>
					</el-input>
				</el-form-item>
				<el-form-item label="bcel订阅秘钥">
					<el-input v-model="state.rateForm.list.bcel_subscribe_key" placeholder="请输入bcel订阅秘钥" />
				</el-form-item>
				<el-form-item label="bcel用户ID">
					<el-input v-model="state.rateForm.list.bcel_user_id" placeholder="请输入bcel用户ID" />
				</el-form-item>
				<el-form-item label="bcel商户ID">
					<el-input v-model="state.rateForm.list.bcel_merchant_id" placeholder="请输入bcel商户ID" />
				</el-form-item>
				<el-form-item label="bcel商户码">
					<el-input v-model="state.rateForm.list.bcel_shop_code" placeholder="请输入bcel商户码" />
				</el-form-item>
				<el-form-item label="bcel商户类型码">
					<el-input v-model="state.rateForm.list.bcel_merchant_category_code" placeholder="请输入bcel商户类型码" />
				</el-form-item>
				<el-form-item label="退款回调地址">
					<el-input v-model="state.rateForm.list.refund_api_url" placeholder="请输入退款回调地址" />
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="onSubmit('rate_config')" :loading="state.submitLoading" size="default">保 存 </el-button>
				</el-form-item>
			</el-form>
			<el-divider content-position="left">提现配置</el-divider>
			<el-form :model="state.userWithdrawLimitForm" inline>
				<el-form-item label="允许提现时间">
					<el-checkbox-group v-model="state.userWithdrawLimitForm.list.days" :min="1">
						<el-checkbox label="星期天" value="0" />
						<el-checkbox label="星期一" value="1" />
						<el-checkbox label="星期二" value="2" />
						<el-checkbox label="星期三" value="3" />
						<el-checkbox label="星期四" value="4" />
						<el-checkbox label="星期五" value="5" />
						<el-checkbox label="星期六" value="6" />
					</el-checkbox-group>
				</el-form-item>
				<el-form-item label="团长最小提现金额">
					<el-input
						v-model="state.userWithdrawLimitForm.list.min_money"
						@input="onVerifyNumberIntegerAndFloatMinMoney"
						placeholder="请输入团长最小提现金额"
					>
						<template #append>元</template>
					</el-input>
				</el-form-item>
				<el-form-item label="团长提现费率">
					<el-input
						v-model="state.userWithdrawLimitForm.list.users_withdraw_rate"
						@input="onVerifyNumberIntegerAndFloatUsesWithdrawRate"
						placeholder="请输入团长提现费率"
					>
						<template #append>%</template>
					</el-input>
				</el-form-item>
				<el-form-item label="供应商提现费率">
					<el-input
						v-model="state.userWithdrawLimitForm.list.supplier_withdraw_rate"
						@input="onVerifyNumberIntegerAndFloatSupplierWithdrawRate"
						placeholder="请输入供应商提现费率"
					>
						<template #append>‰</template>
					</el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="onSubmit('user_withdraw_limit')" :loading="state.submitLoading" size="default">保 存 </el-button>
				</el-form-item>
			</el-form>
			<el-divider content-position="left">积分配置</el-divider>
			<el-form :model="state.integralForm" inline>
				<el-form-item label="商品默认积分">
					<el-input v-model="state.integralForm.list.integral" placeholder="请输入默认积分" @input="onVerifiyNumberIntegerIntegral" />
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="onSubmit('integral_config')" :loading="state.submitLoading" size="default">保 存 </el-button>
				</el-form-item>
			</el-form>
			<el-divider content-position="left">商品库存预警配置</el-divider>
			<el-form :model="state.goodsStockWarmingForm" inline>
				<el-form-item label="预警数值">
					<el-input v-model="state.goodsStockWarmingForm.list.number" placeholder="请输入预警数值" @input="onVerifiyNumberIntegerNumber" />
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="onSubmit('goods_stock_warning')" :loading="state.submitLoading" size="default">保 存 </el-button>
				</el-form-item>
			</el-form>
		</el-card>
	</div>
</template>

<script setup lang="ts" name="basicConfig">
import { ElMessage } from 'element-plus';
import { onMounted, reactive } from 'vue';
import { systemApi } from '/@/api';
import { verifiyNumberInteger, verifyNumberIntegerAndFloat, verifyNumberIntegerAndFloat4 } from '/@/utils/toolsValidate';
import { floatDivide, floatMultiply } from '/@/utils/dictionary';

const SystemApi = systemApi();
// 定义变量内容
const state = reactive({
	material: '',
	commissionForm: {
		identification: 'commission_config',
		name: '佣金配置',
		list: { one_service_rate: '', two_service_rate: '', three_service_rate: '', tow_income_rate: '', three_income_rate: '' },
	},
	h5BasicsForm: {
		identification: 'h5_basics_config',
		name: 'H5基础配置',
		list: { gift_thumb: '', gift_thumb_en: '', gift_thumb_lo: '', app_apk: '', product_review: 1 },
	},
	upgradeForm: {
		identification: 'upgrade_config',
		name: '用户手动升级配置',
		list: { one_to_two: { recommend_num: '', all_num: '' }, two_to_three: { recommend_num: '', all_num: '' } },
	},
	orderForm: {
		identification: 'order_config',
		name: '订单配置',
		list: { auto_cancel: '', cancel_unit: 1, auto_complete: '', complete_unit: 1, auto_settle: '', settle_unit: 1 },
	},
	defaultThreeMobileForm: {
		identification: 'default_three_mobile',
		name: '默认金牌会员手机号',
		list: '',
	},
	youdaoyunForm: {
		identification: 'youdaoyun_config',
		name: '有道云翻译配置',
		list: { appKey: '40f7b534037cb5d8', appSecret: 'Q3t2bTT9vBpuRXkEqgho2KoHI8CIqIBg' },
	},
	chuanglanForm: {
		identification: 'chuanglan_config',
		name: '创蓝短信接口配置',
		list: {
			domestic: { send_url: '', spid: '', password: '' },
			international: { send_url: '', spid: '', password: '' },
		},
	},
	rateForm: {
		identification: 'rate_config',
		name: '支付提现手续费费率配置',
		list: {
			pay_rate: '',
			bcel_subscribe_key: '',
			bcel_user_id: '',
			bcel_merchant_id: '',
			bcel_shop_code: '',
			bcel_merchant_category_code: '',
			refund_api_url: '',
		},
	},
	userWithdrawLimitForm: {
		identification: 'user_withdraw_limit',
		name: '支付提现手续费费率配置',
		list: { days: [3], min_money: '', supplier_withdraw_rate: '', users_withdraw_rate: '' },
	},
	integralForm: {
		identification: 'integral_config',
		name: '积分配置',
		list: { integral: '' },
	},
	goodsStockWarmingForm: {
		identification: 'goods_stock_warning',
		name: '商品库存预警',
		list: { number: '' },
	},
	submitLoading: false,
});
onMounted(() => {
	_configSystemSelect({ identification: state.commissionForm.identification });
	_configSystemSelect({ identification: state.h5BasicsForm.identification });
	_configSystemSelect({ identification: state.upgradeForm.identification });
	_configSystemSelect({ identification: state.orderForm.identification });
	_configSystemSelect({ identification: state.defaultThreeMobileForm.identification });
	_configSystemSelect({ identification: state.youdaoyunForm.identification });
	_configSystemSelect({ identification: state.chuanglanForm.identification });
	_configSystemSelect({ identification: state.rateForm.identification });
	_configSystemSelect({ identification: state.userWithdrawLimitForm.identification });
	_configSystemSelect({ identification: state.integralForm.identification });
	_configSystemSelect({ identification: state.goodsStockWarmingForm.identification });
});

/********** 触发事件 **********/
// 铜牌会员占平台服务费比例过滤
const onVerifyNumberIntegerAndFloatOneServiceRate = (val: string) => {
	state.commissionForm.list.one_service_rate = verifyNumberIntegerAndFloat(val);
};
// 银牌会员占平台服务费比例过滤
const onVerifyNumberIntegerAndFloatTwoServiceRate = (val: string) => {
	state.commissionForm.list.two_service_rate = verifyNumberIntegerAndFloat(val);
};
// 金牌会员占平台服务费比例过滤
const onVerifyNumberIntegerAndFloatThreeServiceRate = (val: string) => {
	state.commissionForm.list.three_service_rate = verifyNumberIntegerAndFloat(val);
};
// 银牌培养收入所占比例
const onVerifyNumberIntegerAndFloatTowIncomeRate = (val: string) => {
	state.commissionForm.list.tow_income_rate = verifyNumberIntegerAndFloat(val);
};
// 金牌培养收入所占比例
const onVerifyNumberIntegerAndFloatThreeIncomeRate = (val: string) => {
	state.commissionForm.list.three_income_rate = verifyNumberIntegerAndFloat(val);
};
// 铜牌升级银牌直推铜牌会员人数过滤
const onVerifiyNumberIntegerOneToTwoRecommendNum = (val: string) => {
	state.upgradeForm.list.one_to_two.recommend_num = verifiyNumberInteger(val);
};
// 铜牌升级银牌团队总人数过滤
const onVerifiyNumberIntegerOneToTwoAllNum = (val: string) => {
	state.upgradeForm.list.one_to_two.all_num = verifiyNumberInteger(val);
};
// 银牌升级金牌直推铜牌会员人数过滤
const onVerifiyNumberIntegerTowToThreeRecommendNum = (val: string) => {
	state.upgradeForm.list.two_to_three.recommend_num = verifiyNumberInteger(val);
};
// 银牌升级金牌团队总人数过滤
const onVerifiyNumberIntegerTowToThreeAllNum = (val: string) => {
	state.upgradeForm.list.two_to_three.all_num = verifiyNumberInteger(val);
};
// 待支付自动关闭时间
const onVerifiyNumberIntegerAutoCancel = (val: string) => {
	state.orderForm.list.auto_cancel = verifiyNumberInteger(val);
};
// 发货自动确认收货时间过滤
const onVerifiyNumberIntegerAutoComplete = (val: string) => {
	state.orderForm.list.auto_complete = verifiyNumberInteger(val);
};
// 确认收货自动结算时间过滤
const onVerifiyNumberIntegerAutoSettle = (val: string) => {
	state.orderForm.list.auto_settle = verifiyNumberInteger(val);
};
// 默认会员手机号过滤
const onVerifiyNumberIntegerMobile = (val: string) => {
	state.defaultThreeMobileForm.list = verifiyNumberInteger(val);
};
// 平台支付费率过滤
const onVerifyNumberIntegerAndFloatPayRate = (val: string) => {
	state.rateForm.list.pay_rate = verifyNumberIntegerAndFloat4(val);
};
// 最小提现金额过滤
const onVerifyNumberIntegerAndFloatMinMoney = (val: string) => {
	state.userWithdrawLimitForm.list.min_money = verifyNumberIntegerAndFloat(val);
};
// 供应商提现费率过滤
const onVerifyNumberIntegerAndFloatSupplierWithdrawRate = (val: string) => {
	state.userWithdrawLimitForm.list.supplier_withdraw_rate = verifyNumberIntegerAndFloat4(val);
};
// 团长提现费率
const onVerifyNumberIntegerAndFloatUsesWithdrawRate = (val: string) => {
	state.userWithdrawLimitForm.list.users_withdraw_rate = verifyNumberIntegerAndFloat4(val);
};
// 商品默认积分
const onVerifiyNumberIntegerIntegral = (val: string) => {
	state.integralForm.list.integral = verifiyNumberInteger(val);
};
// 商品库存预警数值
const onVerifiyNumberIntegerNumber = (val: string) => {
	state.goodsStockWarmingForm.list.number = verifiyNumberInteger(val);
};
// 提交
const onSubmit = (type: string) => {
	switch (type) {
		case 'h5_basics_config':
			const list4 = {
				...state.h5BasicsForm.list,
				gift_thumb_en: state.h5BasicsForm.list.gift_thumb_en || state.h5BasicsForm.list.gift_thumb,
				gift_thumb_lo: state.h5BasicsForm.list.gift_thumb_lo || state.h5BasicsForm.list.gift_thumb,
			};
			_configSystem({
				...state.h5BasicsForm,
				list: JSON.stringify(list4),
			});
			break;
		case 'commission_config':
			const list1 = state.commissionForm.list;
			_configSystem({
				...state.commissionForm,
				list: JSON.stringify({
					one_service_rate: floatDivide(list1.one_service_rate, 100),
					two_service_rate: floatDivide(list1.two_service_rate, 100),
					three_service_rate: floatDivide(list1.three_service_rate, 100),
					tow_income_rate: floatDivide(list1.tow_income_rate, 100),
					three_income_rate: floatDivide(list1.three_income_rate, 100),
				}),
			});
			break;
		case 'upgrade_config':
			_configSystem({
				...state.upgradeForm,
				list: JSON.stringify(state.upgradeForm.list),
			});
			break;
		case 'order_config':
			const info = state.orderForm.list;
			const list = {
				...info,
				auto_cancel: Number(info.auto_cancel) * info.cancel_unit,
				auto_complete: Number(info.auto_complete) * info.complete_unit,
				auto_settle: Number(info.auto_settle) * info.settle_unit,
			};
			_configSystem({
				...state.orderForm,
				list: JSON.stringify(list),
			});
			break;
		case 'default_three_mobile':
			_configSystem({
				...state.defaultThreeMobileForm,
				list: String(state.defaultThreeMobileForm.list),
			});
			break;
		case 'youdaoyun_config':
			_configSystem({
				...state.youdaoyunForm,
				list: JSON.stringify(state.youdaoyunForm.list),
			});
			break;
		case 'chuanglan_config':
			_configSystem({
				...state.chuanglanForm,
				list: JSON.stringify(state.chuanglanForm.list),
			});
			break;
		case 'rate_config':
			const list2 = state.rateForm.list;
			_configSystem({
				...state.rateForm,
				list: JSON.stringify({
					...list2,
					pay_rate: floatDivide(list2.pay_rate, 1000),
				}),
			});
			break;
		case 'user_withdraw_limit':
			const list3 = state.userWithdrawLimitForm.list;
			_configSystem({
				...state.userWithdrawLimitForm,
				list: JSON.stringify({
					...list3,
					supplier_withdraw_rate: floatDivide(list3.supplier_withdraw_rate, 1000),
					users_withdraw_rate: floatDivide(list3.users_withdraw_rate, 100),
					days: list3.days.join(','),
				}),
			});
			break;
		case 'integral_config':
			_configSystem({
				...state.integralForm,
				list: JSON.stringify(state.integralForm.list),
			});
			break;
		case 'goods_stock_warning':
			_configSystem({
				...state.goodsStockWarmingForm,
				list: JSON.stringify(state.goodsStockWarmingForm.list),
			});
			break;
	}
};

/********** 方法事件 **********/

/********** 网络事件 **********/
// 单个系统配置信息
const _configSystemSelect = (params: any) => {
	SystemApi.configSystemSelect(params).then((res) => {
		const info = res.data.info;
		if (!Object.keys(info).length) return;
		switch (params.identification) {
			case 'h5_basics_config':
				state.h5BasicsForm = info.item;
				break;
			case 'commission_config':
				const list1 = info.item.list;
				state.commissionForm = {
					...info.item,
					list: {
						one_service_rate: floatMultiply(list1.one_service_rate, 100),
						two_service_rate: floatMultiply(list1.two_service_rate, 100),
						three_service_rate: floatMultiply(list1.three_service_rate, 100),
						tow_income_rate: floatMultiply(list1.tow_income_rate, 100),
						three_income_rate: floatMultiply(list1.three_income_rate, 100),
					},
				};
				break;
			case 'upgrade_config':
				state.upgradeForm = info.item;
				break;
			case 'order_config':
				const list = info.item.list;
				let cancel_unit = 1;
				let complete_unit = 1;
				let settle_unit = 1;
				if (list.auto_cancel < 60) {
					cancel_unit = 1;
				} else if (list.auto_cancel >= 60 && list.auto_cancel < 3600) {
					cancel_unit = 60;
				} else if (list.auto_cancel >= 3600 && list.auto_cancel < 86400) {
					cancel_unit = 3600;
				} else {
					cancel_unit = 86400;
				}
				if (list.auto_complete < 60) {
					complete_unit = 1;
				} else if (list.auto_complete >= 60 && list.auto_complete < 3600) {
					complete_unit = 60;
				} else if (list.auto_complete >= 3600 && list.auto_complete < 86400) {
					complete_unit = 3600;
				} else {
					complete_unit = 86400;
				}
				if (list.auto_settle < 60) {
					settle_unit = 1;
				} else if (list.auto_settle >= 60 && list.auto_settle < 3600) {
					settle_unit = 60;
				} else if (list.auto_settle >= 3600 && list.auto_settle < 86400) {
					settle_unit = 3600;
				} else {
					settle_unit = 86400;
				}
				state.orderForm = {
					...info.item,
					list: {
						...list,
						auto_cancel: list.auto_cancel / cancel_unit,
						auto_complete: list.auto_complete / complete_unit,
						auto_settle: list.auto_settle / settle_unit,
						cancel_unit,
						complete_unit,
						settle_unit,
					},
				};
				break;
			case 'default_three_mobile':
				state.defaultThreeMobileForm = info.item;
				break;
			case 'youdaoyun_config':
				state.youdaoyunForm = info.item;
				break;
			case 'chuanglan_config':
				state.chuanglanForm = info.item;
				break;
			case 'rate_config':
				const list2 = info.item.list;
				state.rateForm = {
					...info.item,
					list: {
						...list2,
						pay_rate: floatMultiply(list2.pay_rate, 1000),
					},
				};
				break;
			case 'user_withdraw_limit':
				const list3 = info.item.list;
				state.userWithdrawLimitForm = {
					...info.item,
					list: {
						supplier_withdraw_rate: floatMultiply(list3.supplier_withdraw_rate, 1000),
						users_withdraw_rate: floatMultiply(list3.users_withdraw_rate, 100),
						days: list3.days.split(','),
						min_money: list3.min_money,
					},
				};
				break;
			case 'integral_config':
				state.integralForm = info.item;
				break;
			case 'goods_stock_warning':
				state.goodsStockWarmingForm = info.item;
				break;
		}
	});
};
// 保存基本配置
const _configSystem = (params: Object) => {
	SystemApi.configSystem(params)
		.then(() => {
			ElMessage.success('操作成功！');
			state.submitLoading = false;
		})
		.catch(() => {
			state.submitLoading = false;
			_configSystemSelect(params);
		});
};
</script>
